package com.jz.netthings.analysis.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jz.netthings.analysis.bean.JzSubArea;
import com.jz.netthings.analysis.service.JzSubAreaService;
import com.jz.netthings.analysis.service.ProviderInfoDzjwdService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangyunyun
 * @since 2019-07-10
 */
@RestController
@RequestMapping("/adscm/analysis/providerInfoDzjwd")
public class ProviderInfoDzjwdController {

    @Autowired
    ProviderInfoDzjwdService providerInfoDzjwdService;
    @Autowired
    JzSubAreaService jzSubAreaService;

    @Value("${jz.area}")
    int jzAreaNum;
    @Value("${jz.name}")
    String jzName;
    @Value("${jz.wd}")
    String jzWd;
    @Value("${jz.jd}")
    String jzJd;

    /**
     * 格式化地址成标准地址
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/formatDz")
    public SimpleCoreResponse formatDz(String date) throws AdscmSystemException {
        providerInfoDzjwdService.formatDz(date);
        return new SimpleCoreResponse("200", "执行成功", null);
    }
    /**
     *  装载标准地址的经纬度
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadFormatDzJwd")
    public SimpleCoreResponse loadFormatDzJwd() throws AdscmSystemException {
        providerInfoDzjwdService.loadFormatDzJwd();
        return new SimpleCoreResponse("200", "执行成功", null);
    }

    /**
     * 获取某个标准地址的经纬度
     * @param address
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadFormatDzJwdByAddress")
    public SimpleCoreResponse loadFormatDzJwdByAddress(String address) throws AdscmSystemException {
        providerInfoDzjwdService.loadFormatDzJwdByAddress(address);
        return new SimpleCoreResponse("200", "执行成功", null);
    }
    /**
     *  获取所有标准地址和经纬度
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getAllAddress")
    public SimpleCoreResponse getAllAddress() throws AdscmSystemException {
        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.getAllAddress());
    }
    /**
     *  获取所有浆员数量，分布到所有村落
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getAllPNumGroupByVillage")
    public SimpleCoreResponse getAllPNumGroupByVillage() throws AdscmSystemException {
        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.getAllPNumGroupByVillage());
    }
    /**
     *  查询某个日期实时类型（当天新浆员、积极浆员、当天所有浆员）的浆员数量，分布到所有村落
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getAllPNumGroupByVillageByDate")
    public SimpleCoreResponse getAllPNumGroupByVillageByDate(String date) throws AdscmSystemException {
        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.getAllPNumGroupByVillageByDate(date));
    }
    /**
     *  获取某个地址对应的详细统计信息（实时计算）
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadVillageDetailMsg")
    public SimpleCoreResponse loadVillageDetailMsg(String villageName) throws AdscmSystemException {
        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.loadVillageDetailMsg(villageName));
    }
    /**
     *  装载所有地址对应的详细统计信息
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadAllVillageDetailMsg")
    public SimpleCoreResponse loadAllVillageDetailMsg(String villageName) throws AdscmSystemException {
        providerInfoDzjwdService.loadAllVillageDetailMsg(villageName);
        return new SimpleCoreResponse("200", "装载成功", null);
    }

    /**
     * 查询某个地方的浆员某天进站的甘特图
     * @param villageName 村落名称
     * @param date 日期
     * @param isNew 是否当天新浆员（如果为 true，则 无视isPositive条件）
     * @param isPositive 是否当天积极浆员
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getGttByDateVillage")
    public SimpleCoreResponse getGttByDateVillage(String villageName,String date,boolean isNew,boolean isPositive) throws AdscmSystemException {
        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.getGttByDateVillage(villageName,date,isNew,isPositive));
    }


    /**
     * 获取当前浆站所管辖的行政区域
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getJzArea")
    public SimpleCoreResponse getJzArea() throws AdscmSystemException {

        Wrapper<JzSubArea> wrapper = new EntityWrapper<>();
        wrapper.eq("subJz",jzAreaNum);
        return new SimpleCoreResponse("200", "查询成功",jzSubAreaService.selectList(wrapper));
    }
    /**
     * 获取当前浆站坐标
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getJzJwd")
    public SimpleCoreResponse getJzJwd() throws AdscmSystemException {

        Map<String,String > map = new HashMap<>();
        map.put("jzName",jzName);
        map.put("jzWd",jzWd);
        map.put("jzJd",jzJd);

        return new SimpleCoreResponse("200", "查询成功",map);
    }
    /**
     *  查询某个地址对应的详细统计信息（获取统计表中的数据）
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getVillageDetailMsg")
    public SimpleCoreResponse getVillageDetailMsg(String villageName) throws AdscmSystemException {

        return new SimpleCoreResponse("200", "查询成功", providerInfoDzjwdService.getVillageDetailMsg(villageName));
    }

}

